package com.lagou.edu.controller;

import com.lagou.edu.service.DemoService;
import com.lagou.framework.annotation.Autowired;
import com.lagou.framework.annotation.Controller;
import com.lagou.framework.annotation.RequestMapping;
import com.lagou.framework.annotation.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author srh
 * @date 2020/03/15
 **/
@Controller
@Security(value = "root")
@RequestMapping(value = "/demo")
public class DemoController {

    public static final String USERNAME = "username";

    @Autowired
    private DemoService demoService;

    @Security(value = {"zhangsan1", "lisi1"})
    @RequestMapping(value = "/handler1")
    public void handler1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String msg = demoService.handler1();
        resp.getWriter().write(String.format(msg, req.getParameter(USERNAME)));
    }

    @Security(value = {"zhangsan2", "lisi2"})
    @RequestMapping(value = "/handler2")
    public void handler2(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String msg = demoService.handler2();
        resp.getWriter().write(String.format(msg, req.getParameter(USERNAME)));
    }

}
